<template>
  <div class="content">
    <div class="top-bar-lunbo">
      <el-carousel height="800px">
        <el-carousel-item v-for="(item, i) in 4" :key="item">
          <div class="item" v-if="i == 0" style="background-image: url('@/assets/home/b1.jpg')">
          </div>
          <div class="item"  v-if="i == 1" style="background-image: url('../../assets/home/b2.jpg')">
          </div>
          <div class="item" v-if="i == 2" style="background-image: url('../../assets/home/b3.jpg')">
          </div>
          <div  class="item" v-if="i == 3" style="background-image: url('../../assets/home/b4.jpg')">
          </div>
        </el-carousel-item>
      </el-carousel>
    </div>
  </div>
</template>
<script setup>
import { getLeftList, getNewsList, getWebXinxi } from '@/api/viewapi.js'
import { onMounted, ref, reactive } from 'vue'
import { base64Img } from '@/tools/tools.js'
import router from '@/router/index.js';

const LeftList = ref([])
const LeftList2 = ref([])
const newsList = ref([])
const firstData = ref({})
const webxinxi = ref({})

// 左侧列表
const __getLeftData = () => {
  getLeftList().then((res) => {
    LeftList.value = res.data.data
    console.log('左侧信息', res);
    dataReact()
  })
}

// 获取新闻中心
const _getNewsList = () => {
  getNewsList().then((res) => {
    console.log('新闻列表', res);
    newsList.value = res.data.newslist
    firstData.value = res.data.newslist[0]

  })
}

// 获取网站信息
const _getWebXinxi = () => {
  getWebXinxi().then((res) => {

    console.log('网站信息', res);
    webxinxi.value = res.data.data
  })
}

// 跳转详情
const gotoXiangqing = (checkid, newsid) => {
  router.push({
    path: '/newsmessage', query: {
      checkid: checkid, newsid
    }
  })
}
// 跳转详情
const gotoChanpinList = (id) => {
  router.push({ path: '/chanpinlist', query: { id: id } })
}
// 跳转
const gotoChanpinXiangqing = (id) => {
  router.push({ path: '/chanpincontent', query: { id: id } })
}


// 跳转新闻页面
const gotoNewsView = () => {
  router.push({ path: '/news' })
}

// 轮播图数据处理
const dataReact = () => {
  let data = LeftList.value
  let pushData = []
  let item = []
  for (let i = 0; i < data.length; i++) {

    item.push(data[i])

    if (item.length === 6) {
      pushData.push({ item })
      item = []
    }
  }

  // 如果最后剩下不足 3 个元素，仍然需要推入
  if (item.length > 0) {
    pushData.push({ item });
  }

  LeftList2.value = pushData
  console.log('最后结果', pushData);
}

// 获取新闻列表


onMounted(() => {
  __getLeftData()
  _getNewsList()
  _getWebXinxi()
});

</script>
<style lang="scss" scoped>
// 取消显示手机端 显示pc端
@media (min-width: 800px) {
  .content {
    .top-bar-lunbo {
      margin:  0 auto;
      max-width: 1920px;
      .item {
        width: 100vw;
        height: 800px;
      }
    }
  }
}

// 取消显示pc端 显示手机端
@media screen and (max-width: 799px) {}
</style>